home *** CD-ROM | disk | FTP | other *** search
- Path: dildog.lgc.com!usenet
- From: Glenn Carr <gcarr@tulsa.lgc.com>
- Newsgroups: gnu.gcc.help,comp.lang.c
- Subject: gcc 2.7.2 warning: left-hand operand of comma expression has no effect
- Date: Wed, 06 Mar 1996 13:39:53 -0600
- Organization: Landmark Graphics
- Message-ID: <313DEA09.237C@tulsa.lgc.com>
- NNTP-Posting-Host: 134.132.131.47
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; AIX 1)
- CC: "Christopher A. Smith" <casmith@clark.net>
-
- We've just moved from gcc 2.6.3 to 2.7.2 and we're receiving the following new
- warnings (when -Wall is specified)....
-
- warning: left-hand operand of comma expression has no effect
-
-
- When this section of code is encountered in our source files...
-
- static char *rcsid = "$Id: cfgopen.c,v 1.4 1995/12/11 16:04:35 gcarr Exp $";
- #if __GNUC__ == 2
- #define USE(var) static void * use_##var = (&use_##var, (void *) &var)
- USE(rcsid);
- #endif
-
- (This puts the version stamp of each source file in the executable so that we
- can use rcs indent to read the stamps from the exe file if there is a question about
- which source was used to build. The USE macro, fakes gcc into thinking (or used to)
- that 'rcsid' is used when in fact it is not, so that gcc wouldn't complain about
- unused variables if -Wunused is set.)
-
- We also have another frequent occurrence of this problem. We have defined a 'Dbg'
- macro as follows...
-
- void _DbgLog1(char *pszFile, int nLine, char *pszTimeFmt);
- void _DbgLog2(char *pszFmt,...);
- #ifdef DEBUG
- #define Dbg _DbgLog1(__FILE__, __LINE__, DBGLOG_TIMEFMT), _DbgLog2
- #else
- #define Dbg (void)
- #endif /* DEBUG */
-
- We use this for logging debug/trace to stdout if DEBUG is defined. 'Dbg' is defined
- to as two functions in order to print the __FILE__ and __LINE__ along with any printf
- style parameters without explicitly including the __FILE__ and __LINE__ in the Dbg
- call.
-
- Dbg("The value of x is %d\n", x);
-
- ...which outputs something like this...
-
- [file.c,897] The value of x is 32
-
-
- Anyway, can this warning be turned off without turning off -Wall or -Wunused (warns
- about unused variables and labels)? I found this section of code in the gcc source...
-
- ...
-
- /* The left-hand operand of a comma expression is like an expression
- statement: with -W or -Wunused, we should warn if it doesn't have
- any side-effects, unless it was explicitly cast to (void). */
- if ((extra_warnings || warn_unused)
- && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
- && TREE_TYPE (TREE_VALUE (list)) == void_type_node))
- warning ("left-hand operand of comma expression has no effect");
-
- ...
-
- How do I or can I "explicitly cast to (void)" the return value(s) of these
- comma-separated expressions to get rid of these warnings? Or is there another way to
- get rid of these warnings without getting rid of -Wunused? I would prefer to work
- around these two specific problems and continue to get the warning for other cases.
-
- --
- Glenn Carr
- gcarr@lgc.com
- Landmark Graphics
-